﻿<div style="background-color: AppWorkspace;">
    <input type="text" jqxb-datasource="custCompactDetailExt" jqxb-datamember="Name" />
    <input type="text" jqxb-datasource="custCompactDetailExt" jqxb-datamember="Surname" />
    <table>
        <thead>
            <tr>
                <td>
                    Order date
                </td>
                <td>
                    Order Number
                </td>
                <td colspan="2">
                    Action
                </td>
            </tr>
        </thead>
        <tbody jqxb-templatecontainer="custOrdersTpl" jqxb-datasource="custOrders">
            <tr jqxb-template="custOrdersTpl" jqxb-itemdatasourceidx="rowOrder" style="display: none;">
                <td>
                    <input type="text" jqxb-itemdatamember="number" />
                </td>
                <td>
                    <input type="text" jqxb-itemdatamember="date" />
                </td>
                <td>
                </td>
                <td>
                </td>
            </tr>
        </tbody>
    </table>
</div>
<script type="text/javascript">
    /*
    *   jQXB - Dynamic-Widget logic
    *
    */
    var CustomerDetailExt = {}
    CustomerDetailExt.loadCustomer = function (id) {
        jQXB.getJSON('CustomerServices.asmx/getCustomer', { id: id },
                function (data) {
                    jQXB.setDataSource('custCompactDetailExt', data.d).
                         setDataSource('custOrders', data.d.ordersList).
                         doBind('custCompactDetailExt').
                         doBind('custOrders');
                });
    }

    CustomerDetailExt.clearSubscription = function () {
        jQXBM.unsubscribeMessage(jQXBtopics.MSG_CUSTOMER_SELECTED, CustomerDetailExt.loadCustomer);
        jQXBM.unsubscribeMessage(jQXBtopics.MSG_PREPARELOADING, CustomerDetailExt.clearSubscription);
    }

    jQuery(document).ready(function () {

        jQXBM.subscribeMessage(jQXBtopics.MSG_PREPARELOADING, CustomerDetailExt.clearSubscription);
        jQXBM.subscribeMessage(jQXBtopics.MSG_CUSTOMER_SELECTED, CustomerDetailExt.loadCustomer);

    });
</script>
